import numpy as np
import matplotlib.pyplot as plt

f = 10_000  # 10kHz
R = 100     # 100 ohms
C_values = np.logspace(-9, -7, 500)  # 从1nF到100nF
omega = 2 * np.pi * f
phi = np.arctan(omega * R * C_values) * 180 / np.pi  # 角度

plt.figure(figsize=(8, 5))
plt.semilogx(C_values * 1e9, -phi, label="Phase difference")  # 转为nF并取负号
plt.xlabel("Capacitance (nF)")
plt.ylabel("Phase Difference (degrees)")
plt.title("Phase Difference vs Capacitance @10kHz, 100Ω")
plt.grid(True, which="both", ls="--", alpha=0.5)
plt.legend()
plt.tight_layout()
plt.show()
